<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Department</title>
<script type="text/javascript">
	function dpById(id) {
		window.location.href = "${pageContext.request.contextPath}/DepartmentServlet?method=byid&d_id="+id;
	}

	function dpDelete(id) {
		var r = confirm("delete?");
		if (r) {
			window.location.href = "${pageContext.request.contextPath}/DepartmentServlet?method=delete&d_id="+id;
		}
	}
	function selectEmp(id) {
		window.location.href = "${pageContext.request.contextPath}/DepartmentServlet?method=emp&d_id="+id;
	}
</script>

</head>
<body>
	<a href="${pageContext.request.contextPath}/index.jsp">返回</a>
	<p>部门列表</p>
	<form action="${pageContext.request.contextPath}/DepartmentServlet"
		method="post">
		编号<input name="d_id" type="number" /> 名称<input name="d_name"
			type="text" /> 类型<select name="d_type">
			<option value="0"></option>
			<option value="1">部门</option>
			<option value="2">公司</option>
		</select> <input type="submit" /> <input name="method" type="hidden"
			value="part" />
	</form>
	<table border="1">
		<tr>
			<td>编号</td>
			<td>名称</td>
			<td>类型</td>
			<td>电话</td>
			<td>传真</td>
			<td>描述</td>
			<td>上级部门</td>
			<td>成立日期</td>
			<td colspan="2" align="center">操作</td>
		</tr>

		<c:forEach var="dp" items="${departmentList}">
			<tr>
				<td>${dp.d_id}</td>
				<td>${dp.d_name}</td>
				<td>
				<c:if test="${dp.d_type == 1}">部门</c:if> 
				<c:if test="${dp.d_type == 2}">公司</c:if>
				</td>
				<td>${dp.d_phone}</td>
				<td>${dp.d_email}</td>
				<td>${dp.d_describe}</td>
				<td>
				<c:if test="${dp.d_superiorId != 0}">${dp.d_superiorId}</c:if>
				</td>
				<td>${dp.d_startDate}</td>
				<td>
					<button onclick="dpById(${dp.d_id})">编辑</button>
					<button onclick="dpDelete(${dp.d_id})">删除</button>
				</td>
				<td>
				    <button onclick="selectEmp(${dp.d_id})">查看部门下员工</button>
				</td>
			</tr>
		</c:forEach>
	</table>
</body>
</html>